﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Data.SqlClient;   

namespace WindowsFormsApplication4
{
    public partial class FormDangNhap : Form
    {

        
        public FormDangNhap()
        {
            InitializeComponent();
        }


        private void button1_Click(object sender, EventArgs e)
        {


            if (textBox1.Text == "" || textBox1.Text == "" || textBox3.Text == "" || ComboBox.Text == "")
            {
                MessageBox.Show("Ban can dien day du thong tin de dang nhap he thong");
                textBox1.Focus();
                return;
            }
            else
            {
                SqlConnection con = new SqlConnection(@"Data Source=(local);Initial Catalog=LoanPS;Integrated Security=True");
                con.Open();
                SqlCommand cmd = new SqlCommand("select MaPhongBan,NgaySinh,MaNV from nhanvien where MaPhongBan='" + textBox1.Text + "' and NgaySinh='" + textBox2.Text + "'and MaNV='" + textBox3.Text + "'select MaQuyen from QuyenDangNhap where MaQuyen='"+ComboBox.Text+"'", con);
                SqlDataReader reader = cmd.ExecuteReader();

                if (reader.Read())
                    
                {
                    FormMainLPS f1 = new FormMainLPS();
                    
                    f1.txtnguoidung = textBox1.Text.ToString();
                    f1.txtquyen = ComboBox.Text.ToString();
                    f1.Show();
                    MessageBox.Show("ban dang nhap thanh cong duoi ten '" +textBox1.Text+ "'chao mung ban'" +textBox3.Text+ "' den voi he thong", "thong bao");
                    this.Hide();
                }
                else
                {
                    MessageBox.Show("dang nhap that bai xin moi nhap lai", "thong bao");
                }


            }
        }
        private void label2_Click(object sender, EventArgs e)
        {

        }

        private void label4_Click(object sender, EventArgs e)
        {
           
        
       

        }

        private void textBox1_TextChanged(object sender, EventArgs e)
        {

        }

        private void Form1_Load(object sender, EventArgs e)
        {
            // TODO: This line of code loads data into the 'loanPSDataSet.PhanQuyen' table. You can move, or remove it, as needed.
            this.phanQuyenTableAdapter.Fill(this.loanPSDataSet.PhanQuyen);
            // TODO: This line of code loads data into the 'loanPSDataSet.QuyenDangNhap' table. You can move, or remove it, as needed.
            this.quyenDangNhapTableAdapter.Fill(this.loanPSDataSet.QuyenDangNhap);

        }

        private void button3_Click(object sender, EventArgs e)
        {
            DialogResult d1 = MessageBox.Show("ban chac chan muoc thoat khoi chuong trinh", "thong bao", MessageBoxButtons.OKCancel, MessageBoxIcon.Information);
            if(d1==DialogResult.OK)
            Application.Exit();
        }

        private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
        {

        }

        private void label6_Click(object sender, EventArgs e)
        {

        }

        private void pictureBox1_Click(object sender, EventArgs e)
        {

        }

        private void button4_Click(object sender, EventArgs e)
        {
            SqlConnection con = new SqlConnection("Data Source=(local);Initial Catalog=LoanPS;Integrated Security=True");
            con.Open();
            try
            {
                MessageBox.Show("ket noi thanh cong toi he thong co so du lieu SQLserver", "thong bao", MessageBoxButtons.OK, MessageBoxIcon.Information);

            }
            catch(Exception ex)
            {
                MessageBox.Show("ket noi that bai toi he thong co so du lieu SQLserver", "thong bao", MessageBoxButtons.OK, MessageBoxIcon.Error);

            }
        }

        private void quyenDangNhapBindingNavigatorSaveItem_Click(object sender, EventArgs e)
        {
            this.Validate();
            this.quyenDangNhapBindingSource.EndEdit();
            this.tableAdapterManager.UpdateAll(this.loanPSDataSet);

        }

        private void quyenDangNhapComboBox_SelectedIndexChanged(object sender, EventArgs e)
        {

        }

        private void button2_Click(object sender, EventArgs e)
        {
            FormMainLPS f1 = new FormMainLPS();
            f1.Show();
            Hide();
            
        }

        private void groupBox1_Enter(object sender, EventArgs e)
        {

        }

        private void textBox2_TextChanged(object sender, EventArgs e)
        {
            

        }
    }
}
